使用jsonwebtoken时,验证firebase自定义令牌以获取令牌ID失败 您所在的位置:网站首页 jsonwebtoken js 使用jsonwebtoken时,验证firebase自定义令牌以获取令牌ID失败

使用jsonwebtoken时,验证firebase自定义令牌以获取令牌ID失败

#使用jsonwebtoken时,验证firebase自定义令牌以获取令牌ID失败| 来源: 网络整理| 查看: 265

在后端,通过firebase的管理SDK生成自定义令牌:

router.use('/get-token', (req, res) => { var uid = "big-secret"; admin.auth().createCustomToken(uid) .then(function(customToken) { res.json({ instanceID: customToken }); }) .catch(function(error) { console.log("Error creating custom token:", error); }); });

然后客户端前端应用程序选择customToken,然后向后端发出请求以验证:

const fbPrivateKey = serviceAccount.private_key; const key = new NodeRSA(fbPrivateKey).exportKey('pkcs8-public-pem'); router.get('/verifyIdToken', cors(), (req, res) => { jwt.verify(req.headers.authorization.split('Bearer ')[1], key, { algorithms: ['RS256'] }, function(err, decoded) { console.log('err', err); console.log('decoded', decoded); });

这总是错误的消息: JsonWebTokenError: invalid signature

这需要签名吗?如果有人能解释这个或有任何指针?

更新: 当req.headers.authorization.split('Bearer ')[1]通过jwt.io运行时,表示签名无效,但随后我输入我的私钥(key)并进行验证.

我是否使方法调用不正确或将错误的参数传递给jwt.verify()?

1> Hiranya Jaya..:

看起来你正在verifyIdToken使用自定义令牌进行调用.那不行.verifyIdToken只接受"ID令牌".从自定义令牌首次调用获取ID令牌signInWithCustomToken().然后调用getToken()已登录的用户实例.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有